package com.yhsoft.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yhsoft.common.service.TokenService;
import com.yhsoft.flim.controller.response.GetFlimModeInfoOutVo;
import com.yhsoft.goods.controller.requset.AllGoodsInVo;
import com.yhsoft.goods.controller.requset.SetMallUpStatusInVo;
import com.yhsoft.goods.entity.CompanyGoods;
import com.yhsoft.goods.mapper.CompanyGoodsMapper;
import com.yhsoft.goods.service.ICompanyGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 渠道商商品关联表 服务实现类
 * </p>
 *
 * @author yyyyyyyh
 * @since 2023-09-22
 */
@Service
public class CompanyGoodsServiceImpl extends ServiceImpl<CompanyGoodsMapper, CompanyGoods> implements ICompanyGoodsService {

    @Override
    public GetFlimModeInfoOutVo getFlimModeInfo() {
        GetFlimModeInfoOutVo outVo = new GetFlimModeInfoOutVo();
        LambdaQueryWrapper<CompanyGoods> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CompanyGoods::getCompanyId, TokenService.getUserBytoken().getCompanyId());
        wrapper.eq(CompanyGoods::getGoodsId, 0);
        List<CompanyGoods> list = list(wrapper);
        if (list.size() == 1) {
            outVo.setStatusMallUp(list.get(0).getStatusMallUp());
            outVo.setFlimAddPrice(list.get(0).getFlimAddPrice());
        }
        return outVo;
    }

    @Override
    public String setMallUpStatus(SetMallUpStatusInVo inVo) {
        LambdaQueryWrapper<CompanyGoods> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CompanyGoods::getCompanyId, TokenService.getUserBytoken().getCompanyId());
        wrapper.eq(CompanyGoods::getGoodsId, inVo.getGoodsId());
        CompanyGoods companyGoods = getOne(wrapper);
        if (companyGoods != null) {
            companyGoods.setStatusMallUp(inVo.getStatusMallUp());
            updateById(companyGoods);
            return "success";
        }
        return null;
    }
}
